package com.csgc.camera.widget.mask

import android.content.Context
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.storage.MaskPreference
import com.cysd.spsyxj.R


class MaskProject:MaskBase {

    private var projectArea:TextView?=null
    private var projectName:TextView?=null
    private var projectContent:TextView?=null
    private var projectPerson:TextView?=null
    private var projectCompany:TextView?=null
    constructor(context: Context?, id:Int) : super(context,null){
        if(id == 0){
            customTextColor = ContextCompat.getColor(context!!,R.color.color_333333)
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_project_1, this, true)
        }else if(id == 1){
            customTextColor = ContextCompat.getColor(context!!,R.color.color_333333)
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_project_2, this, true)
        }else if(id == 2){
            customTextColor = ContextCompat.getColor(context!!,R.color.color_333333)
            dateStyle = "yyyy-MM-dd EEEE HH:mm"
            LayoutInflater.from(context).inflate(R.layout.item_mask_project_3, this, true)
        }else if(id == 3){
            customTextColor = ContextCompat.getColor(context!!,R.color.color_333333)
            dateStyle = "yyyy-MM-dd EEEE HH:mm"
            LayoutInflater.from(context).inflate(R.layout.item_mask_project_4, this, true)
        }else if(id == 4){
            remarkNeedTitle = false
            customTextColor = ContextCompat.getColor(context!!,R.color.color_333333)
            dateStyle = "yyyy-MM-dd EEEE HH:mm"
            LayoutInflater.from(context).inflate(R.layout.item_mask_project_5, this, true)
        }

        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView()

    }

    private fun initView(){
        date = findViewById(R.id.tv_project_date)
        location = findViewById(R.id.tv_project_location)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)

        remark = findViewById(R.id.tv_project_remark)
        remarkLayout = findViewById(R.id.layout_project_remark)

        projectArea = findViewById(R.id.tv_project_area)
        projectName = findViewById(R.id.tv_project_name)
        projectContent = findViewById(R.id.tv_project_content)
        projectPerson = findViewById(R.id.tv_project_person)
        projectCompany = findViewById(R.id.tv_project_company)



        location?.text = MaskConfig.maskLocation
        changeDateTime()

        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(customTextColor)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,12f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }


        val maskType = MaskPreference.instance.getMaskType()

        MaskConfig.maskMap[maskType]?.forEach {
            if (it.title == "施工区域"){
                projectArea?.text = it.content
            }else if (it.title == "施工内容"){
                projectContent?.text = it.content
            }else if (it.title == "责任人"){
                projectPerson?.text = it.content
            }else if (it.title == "施工单位"){
                projectCompany?.text = it.content
            } else if (it.title == "工程名称"){
                projectName?.text = it.content
            }
        }


    }


    override fun updateItemContent(title: String, content: String) {
        super.updateItemContent(title, content)
        if (title == "施工区域"){
            projectArea?.text = content
        }else if (title == "施工内容"){
            projectContent?.text = content
        }else if (title == "责任人"){
            projectPerson?.text = content
        }else if (title == "施工单位"){
            projectCompany?.text = content
        } else if (title == "工程名称"){
            projectName?.text = content
        }

    }

}